/*
 * @Description: 
 * @Author: 平常心
 * @Date: 2024-09-30 10:30:25
 * @LastEditTime: 2024-09-30 10:37:01
 * @LastEditors: 平常心
 * @FilePath: \java\day26\Test02Student.java
 * 至若春和景明
 */

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test02Student {
    public static void main(String[] args) {
        // 创建Map对象
        Map<Student, String> map = new HashMap<>();
        // 创建Student对象,因为Student是自定义类型,包含多个数据类型,所以在存储的时候,要通过对象存储
        Student s1 = new Student("张三", 18);
        Student s2 = new Student("李四", 19);
        Student s3 = new Student("王五", 20);
        // 添加元素
        map.put(s1, "001");
        map.put(s2, "002");
        map.put(s3, "003");
        System.out.println("map: " + map);
        // 遍历
        Set<Student> set = map.keySet();
        for (Student student : set) {
            System.out.println("key:" + student + " value:" + map.get(student));
        }
        // 遍历
        Set<Map.Entry<Student, String>> entrySet = map.entrySet();
        for (Map.Entry<Student, String> entry : entrySet) {
            System.out.println("key:" + entry.getKey() + " value:" + entry.getValue());
        }

    }
}
